//
//  UIImage+RoundRect.m
//  INMOTION
//
//  Created by Kyle Sun on 11/6/15.
//  Copyright © 2015 Inmotion. All rights reserved.
//

#import "UIImage+RoundRect.h"

@implementation UIImage (RoundRect)

- (UIImage *)roundRectImageWithCornerRadius:(CGFloat)cornerRadius bounds:(CGRect)bounds {
    UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0.0);
    
    // Add a clip before drawing anything, in the shape of an rounded rect
    [[UIBezierPath bezierPathWithRoundedRect:bounds
                                cornerRadius:cornerRadius] addClip];
    // Draw your image
    [self drawInRect:bounds];
    
    // Get the image, here setting the UIImageView image
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    // Lets forget about that we were drawing
    UIGraphicsEndImageContext();
    
    return image;
}

@end
